package tienmanh.gs.goldminer.util;

import java.util.ArrayList;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import tienmanh.gs.goldminer.manager.ResourcesManager;

public class Value
{
  public int BAG = 1;
  public int TNT = 10;
  
  public int JEWEL_0 = 300;
  public int JEWEL_1 = 300;
  public int JEWEL_2 = 300;
  public int JEWEL_3 = 600;
  public int JEWEL_4 = 500;
  public int JEWEL_5 = 500;
  public int JEWEL_6 = 500;
  public int JEWEL_7 = 1000;
  public int JEWEL_8 = 800;
  public int JEWEL_9 = 800;
  public int JEWEL_10 = 800;
  public int JEWEL_11 = 1600;
  
  public int GOLD_0 = 30;
  public int GOLD_1 = 100;
  public int GOLD_2 = 300;
  public int GOLD_3 = 50;
  public int GOLD_4 = 150;
  public int GOLD_5 = 500;
  
  public int MOUSE_0 = 20;
  public int MOUSE_1 = 50;
  public int MOUSE_2 = 1000;
  public int MOUSE_3 = 50;
  public int MOUSE_4 = 50;
  
  public int STONE_0 = 10;
  public int STONE_01 = 20;
  public int STONE_02 = 30;
  public int STONE_1 = 50;
  
  public int FISH_0 = 100;
  public int FISH_1 = 300;
  public int FISH_E = 300;
  public int FISH_2 = 50;
  public int FISH_21 = 500;
  public int FISH_3 = 50;
  
  public int NGOCTRAI = 0;
  
  
  
  public float HEIGHT_BEZEL_PIG = ResourcesManager.getInstance().ttrMouse1.getHeight();
  public float HEIGHT_BEZEL_PIG1 = ResourcesManager.getInstance().ttrMouse2.getHeight();
  public float HEIGHT_BEZEL_PIGBEAT = ResourcesManager.getInstance().ttrMouseBeat.getHeight();
  public float HEIGHT_ELEFISH = ResourcesManager.getInstance().ttrElecFish.getHeight()/3;
  public float HEIGHT_FISH1 = ResourcesManager.getInstance().ttrFish1.getHeight()/3;
  public float HEIGHT_FISH2 = ResourcesManager.getInstance().ttrFish2.getHeight()/3;
  public float HEIGHT_FISH3 = ResourcesManager.getInstance().ttrFish3.getHeight();
  public float HEIGHT_FISH4 = ResourcesManager.getInstance().ttrFish4.getHeight();
  public float HEIGHT_FISH5 = ResourcesManager.getInstance().ttrFish5.getHeight()/3;
  public float HEIGHT_CHEST = ResourcesManager.getInstance().textureRegionChest.getHeight();
  public float HEIGHT_GEM = 100;
  public float HEIGHT_GOLD_0 = ResourcesManager.getInstance().textureRegionGold0.getHeight()/2;
  public float HEIGHT_GOLD_1 = ResourcesManager.getInstance().textureRegionGold1.getHeight()/2;
  public float HEIGHT_GOLD_2 = ResourcesManager.getInstance().textureRegionGold2.getHeight()/2;
  public float HEIGHT_GOLD_3 = ResourcesManager.getInstance().textureRegionGold3.getHeight()/2;
  public float HEIGHT_GOLD_4 = ResourcesManager.getInstance().textureRegionGold4.getHeight()/2;
  public float HEIGHT_GOLD_5 = ResourcesManager.getInstance().textureRegionGold5.getHeight()/2;
  public float HEIGHT_STONE_0 = ResourcesManager.getInstance().textureStone0.getHeight();
  public float HEIGHT_STONE_01 = ResourcesManager.getInstance().textureStone01.getHeight(); 
  public float HEIGHT_STONE_02 =ResourcesManager.getInstance().textureStone02.getHeight();
  public float HEIGHT_STONE_1 = 65;
  public float HEIGHT_TNT = ResourcesManager.getInstance().textureRegionTNT.getHeight()/2;
  public float HEIGHT_JEWEL0 = ResourcesManager.getInstance().textureRegionJewel0.getHeight();
  public float HEIGHT_JEWEL1 = ResourcesManager.getInstance().textureRegionJewel1.getHeight();
  public float HEIGHT_JEWEL2 = ResourcesManager.getInstance().textureRegionJewel2.getHeight();
  public float HEIGHT_BARIE =ResourcesManager.getInstance().textureRegionBarier.getHeight(); 
  public float HEIGHT_MINER =ResourcesManager.getInstance().ttrMiner.getHeight()/2; 
  
  
  public float MAX_LEVEL = 30;
  
  public float WIDTH_BEZEL_PIG = ResourcesManager.getInstance().ttrMouse1.getWidth();
  public float WIDTH_BEZEL_PIG1 = ResourcesManager.getInstance().ttrMouse2.getWidth();
  public float WIDTH_BEZEL_PIGBEAT = ResourcesManager.getInstance().ttrMouseBeat.getWidth();
  public float WIDTH_ELEFISH = ResourcesManager.getInstance().ttrElecFish.getWidth()/3;
  public float WIDTH_FISH1 = ResourcesManager.getInstance().ttrFish1.getWidth()/3;
  public float WIDTH_FISH2 = ResourcesManager.getInstance().ttrFish2.getWidth()/3;
  public float WIDTH_FISH3 = ResourcesManager.getInstance().ttrFish3.getWidth();
  public float WIDTH_FISH4 = ResourcesManager.getInstance().ttrFish4.getWidth();
  public float WIDTH_FISH5 = ResourcesManager.getInstance().ttrFish5.getWidth()/3;
  public float WIDTH_CHEST = ResourcesManager.getInstance().textureRegionChest.getWidth();
  public float WIDTH_GEM = 61;
  public float WIDTH_GOLD_0 = ResourcesManager.getInstance().textureRegionGold0.getWidth()/2;
  public float WIDTH_GOLD_1 = ResourcesManager.getInstance().textureRegionGold1.getWidth()/2;
  public float WIDTH_GOLD_2 = ResourcesManager.getInstance().textureRegionGold2.getWidth()/2;
  public float WIDTH_GOLD_3 = ResourcesManager.getInstance().textureRegionGold3.getWidth()/2;
  public float WIDTH_GOLD_4 = ResourcesManager.getInstance().textureRegionGold4.getWidth()/2;
  public float WIDTH_GOLD_5 = ResourcesManager.getInstance().textureRegionGold5.getWidth()/2;
  public float WIDTH_STONE_0 = ResourcesManager.getInstance().textureStone0.getWidth();;
  public float WIDTH_STONE_01 = ResourcesManager.getInstance().textureStone01.getWidth(); 
  public float WIDTH_STONE_02 =ResourcesManager.getInstance().textureStone02.getWidth();
  public float WIDTH_STONE_1 = 60;
  public float WIDTH_TNT = ResourcesManager.getInstance().textureRegionTNT.getWidth()/2;
  public float WIDTH_JEWEL0 = ResourcesManager.getInstance().textureRegionJewel0.getWidth();
  public float WIDTH_JEWEL1 = ResourcesManager.getInstance().textureRegionJewel1.getWidth();
  public float WIDTH_JEWEL2 = ResourcesManager.getInstance().textureRegionJewel2.getWidth();
  public float WIDTH_BARIE =ResourcesManager.getInstance().textureRegionBarier.getWidth();
  public float WWIDTH_MINER =ResourcesManager.getInstance().ttrMiner.getWidth()/2; 
  
  public int PRICE_DIAMOND = 100;
  public int PRICE_MINE = 100;
  public int PRICE_TIME = 100;
  
  public float SPEED_BEZEL = 3.0F;
  public float SPEED_BEZEL_PIG = 100.0F;
  public float SPEED_CHEST = 70.0F;
  public float SPEED_GOLD_0 = 80.0F;
  public float SPEED_GOLD_1 = 70.5F;
  public float SPEED_GOLD_2 = 50.0F;
  public float SPEED_GOLD_3 = 40.5F;
  public float SPEED_STONE_0 = 45.0F;
  public float SPEED_STONE_1 = 30.5F;
  public float SPEED_TNT = 300F;
  public float SPEED_NGOCTRAI = 200F;
  
  
  
  
  public String TAG_ENTITY = "entity";
  public String TAG_ENTITY_ATTRIBUTE_HEIGHT = "height";
  public String TAG_ENTITY_ATTRIBUTE_TYPE = "type";
  public String TAG_ENTITY_ATTRIBUTE_WIDTH = "width";
  public String TAG_ENTITY_ATTRIBUTE_X = "x";
  public String TAG_ENTITY_ATTRIBUTE_Y = "y";
  
  
  public String TYPE_BEZEL = "bezel";
  public String TYPE_BEZEL_PIG_1 = "bezel_pig_1";
  public String TYPE_BEZEL_PIG_2 = "bezel_pig_2";
  public String TYPE_BEZEL_PIG_3 = "bezel_pig_3";
  public String TYPE_BEZEL_PIG_4 = "bezel_pig_4";
  public String TYPE_BEZEL_PIG_5 = "bezel_pig_quai";
  public String TYPE_CHEST = "chest";
  public String TYPE_GOLD_0 = "gold0";
  public String TYPE_GOLD_1 = "gold1";
  public String TYPE_GOLD_2 = "gold2";
  public String TYPE_GOLD_3 = "gold3";
  public String TYPE_GOLD_4 = "gold4";
  public String TYPE_GOLD_5 = "gold5";
  public String TYPE_JEWEL_0 = "jewe0";
  public String TYPE_JEWEL_1 = "jewe1";
  public String TYPE_JEWEL_2 = "jewe2";
  public String TYPE_JEWEL_3 = "jewe3";
  public String TYPE_JEWEL_4 = "jewe4";
  public String TYPE_JEWEL_5 = "jewe5";
  public String TYPE_JEWEL_6 = "jewe6";
  public String TYPE_JEWEL_7 = "jewe7";
  public String TYPE_JEWEL_8 = "jewe8";
  public String TYPE_JEWEL_9 = "jewe9";
  public String TYPE_JEWEL_10 = "jewel0";
  public String TYPE_JEWEL_11 = "jewel1";
  public String TYPE_STONE_0 = "stone0";
  public String TYPE_STONE_1 = "stone1";
  public String TYPE_STONE_2 = "stone2";
  public String TYPE_STONE_3 = "stone3";
  public String TYPE_TNT = "tnt";
  public String TYPE_NGOCTRAIDEN = "ngoctraiden";
  public String TYPE_NGOCTRAITRANG = "ngoctraitrang";
  public String TYPE_ELECTRICFISH = "electrichfish";
  public String TYPE_FISH1 = "fish1";
  public String TYPE_FISH2 = "fish2";
  public String TYPE_FISH3 = "fish3";
  public String TYPE_FISH4 = "fish4";
  public String TYPE_FISH5 = "fish5";
  public String TYPE_BARIE = "barie";
  
  public int[][] map;

  public Value()
  {
    int[][] arrayOfInt = new int[10][];
    int[] arrayOfInt1 = new int[11];
    arrayOfInt1[1] = 1;
    arrayOfInt1[2] = 1;
    arrayOfInt1[3] = 4;
    arrayOfInt1[4] = 5;
    arrayOfInt1[5] = 1;
    arrayOfInt1[6] = 1;
    arrayOfInt1[7] = 1;
    arrayOfInt[0] = arrayOfInt1;
    int[] arrayOfInt2 = new int[11];
    arrayOfInt2[0] = 1;
    arrayOfInt2[1] = 2;
    arrayOfInt2[3] = 3;
    arrayOfInt2[4] = 8;
    arrayOfInt2[5] = 2;
    arrayOfInt2[6] = 2;
    arrayOfInt[1] = arrayOfInt2;
    int[] arrayOfInt3 = new int[11];
    arrayOfInt3[0] = 1;
    arrayOfInt3[1] = 1;
    arrayOfInt3[3] = 2;
    arrayOfInt3[4] = 8;
    arrayOfInt3[5] = 2;
    arrayOfInt3[6] = 2;
    arrayOfInt[2] = arrayOfInt3;
    int[] arrayOfInt4 = new int[11];
    arrayOfInt4[2] = 2;
    arrayOfInt4[3] = 2;
    arrayOfInt4[4] = 4;
    arrayOfInt4[5] = 2;
    arrayOfInt4[6] = 1;
    arrayOfInt4[7] = 2;
    arrayOfInt4[8] = 1;
    arrayOfInt[3] = arrayOfInt4;
    int[] arrayOfInt5 = new int[11];
    arrayOfInt5[0] = 3;
    arrayOfInt5[1] = 2;
    arrayOfInt5[2] = 2;
    arrayOfInt5[3] = 3;
    arrayOfInt5[4] = 3;
    arrayOfInt5[5] = 1;
    arrayOfInt5[6] = 1;
    arrayOfInt5[7] = 1;
    arrayOfInt[4] = arrayOfInt5;
    int[] arrayOfInt6 = new int[11];
    arrayOfInt6[1] = 1;
    arrayOfInt6[3] = 4;
    arrayOfInt6[4] = 5;
    arrayOfInt6[7] = 1;
    arrayOfInt6[8] = 2;
    arrayOfInt6[9] = 1;
    arrayOfInt[5] = arrayOfInt6;
    int[] arrayOfInt7 = new int[11];
    arrayOfInt7[1] = 3;
    arrayOfInt7[2] = 2;
    arrayOfInt7[4] = 2;
    arrayOfInt7[5] = 1;
    arrayOfInt7[6] = 1;
    arrayOfInt7[7] = 1;
    arrayOfInt7[9] = 1;
    arrayOfInt7[10] = 2;
    arrayOfInt[6] = arrayOfInt7;
    int[] arrayOfInt8 = new int[11];
    arrayOfInt8[0] = 8;
    arrayOfInt8[8] = 2;
    arrayOfInt8[9] = 2;
    arrayOfInt8[10] = 2;
    arrayOfInt[7] = arrayOfInt8;
    int[] arrayOfInt9 = new int[11];
    arrayOfInt9[0] = 3;
    arrayOfInt9[2] = 3;
    arrayOfInt9[3] = 2;
    arrayOfInt9[4] = 2;
    arrayOfInt9[5] = 1;
    arrayOfInt9[8] = 2;
    arrayOfInt9[9] = 2;
    arrayOfInt9[10] = 2;
    arrayOfInt[8] = arrayOfInt9;
    int[] arrayOfInt10 = new int[11];
    arrayOfInt10[0] = 8;
    arrayOfInt10[8] = 2;
    arrayOfInt10[9] = 2;
    arrayOfInt10[10] = 7;
    arrayOfInt[9] = arrayOfInt10;
    this.map = arrayOfInt;
  }

  public String getType(int paramInt)
  {
    switch (paramInt)
    {
    case 0:
      return this.TYPE_JEWEL_4;
    case 1:
      return this.TYPE_JEWEL_5;
    case 2:
      return this.TYPE_JEWEL_6;
    case 3:
      return this.TYPE_JEWEL_7;
    case 4:
      return this.TYPE_JEWEL_8;
    case 5:
      return this.TYPE_JEWEL_9;
    case 6:
      return this.TYPE_JEWEL_10;
    case 7:
      return this.TYPE_JEWEL_11;
    case 8:
      return this.TYPE_JEWEL_0;
    case 9:
      return this.TYPE_JEWEL_1;
    case 10:
      return this.TYPE_JEWEL_2;
    case 11:
      return this.TYPE_JEWEL_3;
    case 12:
        return this.TYPE_GOLD_5;
    case 13:
        return this.TYPE_GOLD_4;
    case 14:
        return this.TYPE_GOLD_3;
    case 15:
        return this.TYPE_GOLD_2;
    case 16:
        return this.TYPE_GOLD_1;
    case 17:
        return this.TYPE_GOLD_0;
    case 18:
        return this.TYPE_STONE_2;
    case 19:
        return this.TYPE_STONE_1;
    case 20:
        return this.TYPE_STONE_0;
    case 21:
        return this.TYPE_STONE_3;
    case 22:
        return this.TYPE_BEZEL_PIG_1;
    case 23:
        return this.TYPE_BEZEL_PIG_4;
    case 24:
        return this.TYPE_BEZEL_PIG_3;
    case 25:
        return this.TYPE_BEZEL_PIG_2;
    case 26:
        return this.TYPE_BEZEL_PIG_5;
    case 27:
        return this.TYPE_FISH1;
    case 28:
        return this.TYPE_FISH2;
    case 29:
        return this.TYPE_ELECTRICFISH;
    case 30:
        return this.TYPE_FISH4;
    case 31:
        return this.TYPE_FISH3;
    case 32:
        return this.TYPE_BARIE;
      case 33:
        return this.TYPE_FISH5;
      case 34:
        return this.TYPE_NGOCTRAITRANG;
      case 35:
        return this.TYPE_NGOCTRAITRANG;
      case 36:
        return this.TYPE_NGOCTRAIDEN;
      case 37:
        return this.TYPE_TNT;
      case 38:
        return this.TYPE_CHEST;
    default:
        return "";
    }
  }

  	ParseJson parse = new ParseJson();
	private JSONObject object;
	private JSONArray mapArr;
	
	private static final String YEUCAU = "requiregold";
	private static final String OBJECT= "object";
	private static final String MAP = "map";
	private static final String TIME = "time";
	private static final String ID = "id";
	private static final String POSITION = "pos";
	private static final String POSITIONEND = "posend";
	private static final String ANGLE = "angle";
  
  public MapObject getObjectInMap(int lev) throws Exception{
	  MapObject objMap = new MapObject();
	  object = parse.getJSONFromUrl();
	  
		  mapArr = object.getJSONArray(MAP);
		  JSONObject c = mapArr.getJSONObject(lev-1);
		    JSONArray arr = c.getJSONArray(MAP+(lev));
		      
		    int time = Integer.parseInt(arr.getJSONObject(0).getString(TIME).trim());
		    int require = Integer.parseInt(arr.getJSONObject(0).getString(YEUCAU).trim());
		    JSONArray arr1 = arr.getJSONObject(0).getJSONArray(OBJECT);
		    ArrayList<Object>  obj = new ArrayList<Object>();
			for (int i = 0; i < arr1.length(); i++) {
					JSONObject c1 = arr1.getJSONObject(i);
					String id = c1.getString(ID).trim();
					String pos = c1.getString(POSITION).trim();
					String posend = c1.getString(POSITIONEND);
					String angle = c1.getString(ANGLE);
					 ArrayList<Object>  subObj = returnRandomValue(id, pos,posend,angle);
					 System.out.println(posend);
					 for (int j = 0; j < subObj.size(); j++) {
						obj.add(subObj.get(j));
					}
				}
	      objMap = new MapObject(time, require, obj);
	  return objMap;
  }
  
  public ArrayList<Object> returnRandomValue(String id , String pos , String posend,String angle){
	  ArrayList<Object> object = new ArrayList<Object>();
	  Random r = new Random();
	  int valueID;
	  String[] arrID = id.split(";");
	  String[] arrPOS = pos.split(";");
		  valueID = Integer.parseInt(arrID[r.nextInt(arrID.length)].trim());
		for (int i = 0; i < arrPOS.length; i++) {
			 String position[] = arrPOS[i].split(",");
			    object.add(new Object(Integer.parseInt(position[0].trim()), Integer.parseInt(position[1].trim()),Integer.parseInt(posend.split(",")[0].trim()),Integer.parseInt(posend.split(",")[1].trim()), ""+valueID,Integer.parseInt(angle)));
	  }
	  
	  return object;
  }
  
}

